package Dungeoneering.PathFinding;

import java.awt.Point;
import java.util.ArrayList;

import Dungeoneering.Entities.Room.Direction;

/**
 * A path resembles a series of rooms that we have to traverse to go from one room to another
 * @author Nicolaas
 *
 */
public class Path {
	
	private ArrayList<PathNode> list;
	private int selectedIndex;
	
	public Path() {
		list = new ArrayList<PathNode>();
		selectedIndex = 0;
	}
	
	public void push(PathNode node) {
		list.add(node);
	}
	
	public void pop() {
		list.remove(list.size() - 1);
	}
	
	public int getLength() {
		return list.size();
	}
	
	public boolean hasNext() {
		return selectedIndex < list.size() - 1 && !list.get(selectedIndex).isEndNode();
	}
	
	public Direction next() {
		return list.get(selectedIndex++).getDirectionToNextNode();
	}
	
	/**
	 * will try to find a node in this path with given map coords
	 * @param mapCoords the coords of the room on the map
 	 * @return true if it is found
	 */
	public boolean contains(Point mapCoords) {
		for (PathNode pn : list) {
			if (pn.getCoords().equals(mapCoords))
				return true;
		}
		return false;
	}

}
